# cmake -DCMAKE_C_COMPILER:FILEPATH=%LINUXROOT%\\mingw64_14_2_0\\bin\\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=%LINUXROOT%\\mingw64_14_2_0\\bin\\g++.exe -G "MinGW Makefiles"
# -DCMAKE_INSTALL_PREFIX=%LINUXROOT%
cmake_minimum_required(VERSION 3.5.0)
project(OpenGL VERSION 0.1.0 LANGUAGES C CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++ -Wno-error=deprecated-declarations -O2 -Wno-deprecated-declarations")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error=deprecated-declarations -O2 -Wno-deprecated-declarations")

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD 11)

if(DEFINED ENV{LINUXROOT})
    set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH};$ENV{LINUXROOT}\\lib\\pkgconfig;")
    message(STATUS "<cmake out> ENV{PKG_CONFIG_PATH} is: " $ENV{PKG_CONFIG_PATH})
endif()

include(FindPkgConfig)
pkg_check_modules(PKGS REQUIRED 
    glfw3
    glew
)
add_definitions(-DPROJECT_ROOT="${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "<cmake out> PROJECT_ROOT is: " ${CMAKE_CURRENT_SOURCE_DIR})

find_package(OpenGL REQUIRED)

# 使用网络连接 glm
include(FetchContent)

FetchContent_Declare(
	glm
	GIT_REPOSITORY	https://github.com/g-truc/glm.git
	GIT_TAG 	bf71a834948186f4097caa076cd2663c69a10e1e #refs/tags/1.0.1
)

FetchContent_MakeAvailable(glm)

# 连接本地库
# find_package(glm CONFIG REQUIRED)
#

set(GLM_LIB glm::glm)

message(STATUS "<cmake out> PKGS_LDFLAGS is: " ${PKGS_LDFLAGS})
message(STATUS "<cmake out> PKGS_INCLUDE_DIRS is: " ${PKGS_INCLUDE_DIRS})
message(STATUS "<cmake out> PKGS_CFLAGS is: " ${PKGS_CFLAGS})

foreach(include_dir ${PKGS_INCLUDE_DIRS})
    set(my_pkgs_include_dirs "${my_pkgs_include_dirs} ${include_dir}")
endforeach(include_dir)

foreach(cflags ${PKGS_CFLAGS})
    set(my_pkgs_cflags "${my_pkgs_cflags} ${cflags}")
endforeach(cflags)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_pkgs_cflags}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_pkgs_cflags}")

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/src
    ${my_pkgs_include_dirs}
)

file(GLOB_RECURSE
    cxx_sourceFile
        ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp
)

add_executable(${PROJECT_NAME} 
    ${cxx_sourceFile}
)

target_link_libraries(${PROJECT_NAME} 
    PUBLIC 
    pthread
    ${PKGS_LDFLAGS}
    ${OPENGL_LIBRARIES}
    ${GLM_LIB}
)